using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace SurveyHost.Core.DAL
{
	/// <summary>
	/// Strongly-typed collection for the HostConfiguration class.
	/// </summary>
	[Serializable]
	public partial class HostConfigurationCollection : ActiveList<HostConfiguration, HostConfigurationCollection> 
	{	   
		public HostConfigurationCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the HostConfiguration table.
	/// </summary>
	[Serializable]
	public partial class HostConfiguration : ActiveRecord<HostConfiguration>
	{
		#region .ctors and Default Settings
		
		public HostConfiguration()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public HostConfiguration(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

		public HostConfiguration(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public HostConfiguration(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor
		public static Query CreateQuery() { return new Query(Schema); }

		
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("HostConfiguration", TableType.Table, DataService.GetInstance("SurveyHost"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarHostName = new TableSchema.TableColumn(schema);
				colvarHostName.ColumnName = "HostName";
				colvarHostName.DataType = DbType.String;
				colvarHostName.MaxLength = 200;
				colvarHostName.AutoIncrement = false;
				colvarHostName.IsNullable = false;
				colvarHostName.IsPrimaryKey = true;
				colvarHostName.IsForeignKey = false;
				colvarHostName.IsReadOnly = false;
				colvarHostName.DefaultSetting = @"";
				colvarHostName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarHostName);
				
				TableSchema.TableColumn colvarSurveyName = new TableSchema.TableColumn(schema);
				colvarSurveyName.ColumnName = "SurveyName";
				colvarSurveyName.DataType = DbType.String;
				colvarSurveyName.MaxLength = 50;
				colvarSurveyName.AutoIncrement = false;
				colvarSurveyName.IsNullable = false;
				colvarSurveyName.IsPrimaryKey = false;
				colvarSurveyName.IsForeignKey = false;
				colvarSurveyName.IsReadOnly = false;
				colvarSurveyName.DefaultSetting = @"";
				colvarSurveyName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarSurveyName);
				
				TableSchema.TableColumn colvarAdministratorName = new TableSchema.TableColumn(schema);
				colvarAdministratorName.ColumnName = "AdministratorName";
				colvarAdministratorName.DataType = DbType.String;
				colvarAdministratorName.MaxLength = 50;
				colvarAdministratorName.AutoIncrement = false;
				colvarAdministratorName.IsNullable = false;
				colvarAdministratorName.IsPrimaryKey = false;
				colvarAdministratorName.IsForeignKey = false;
				colvarAdministratorName.IsReadOnly = false;
				colvarAdministratorName.DefaultSetting = @"";
				colvarAdministratorName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAdministratorName);
				
				TableSchema.TableColumn colvarInvitationEmail = new TableSchema.TableColumn(schema);
				colvarInvitationEmail.ColumnName = "InvitationEmail";
				colvarInvitationEmail.DataType = DbType.String;
				colvarInvitationEmail.MaxLength = 5000;
				colvarInvitationEmail.AutoIncrement = false;
				colvarInvitationEmail.IsNullable = false;
				colvarInvitationEmail.IsPrimaryKey = false;
				colvarInvitationEmail.IsForeignKey = false;
				colvarInvitationEmail.IsReadOnly = false;
				colvarInvitationEmail.DefaultSetting = @"";
				colvarInvitationEmail.ForeignKeyTableName = "";
				schema.Columns.Add(colvarInvitationEmail);
				
				TableSchema.TableColumn colvarCompletionEmail = new TableSchema.TableColumn(schema);
				colvarCompletionEmail.ColumnName = "CompletionEmail";
				colvarCompletionEmail.DataType = DbType.String;
				colvarCompletionEmail.MaxLength = 5000;
				colvarCompletionEmail.AutoIncrement = false;
				colvarCompletionEmail.IsNullable = false;
				colvarCompletionEmail.IsPrimaryKey = false;
				colvarCompletionEmail.IsForeignKey = false;
				colvarCompletionEmail.IsReadOnly = false;
				colvarCompletionEmail.DefaultSetting = @"";
				colvarCompletionEmail.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCompletionEmail);
				
				TableSchema.TableColumn colvarAdministratorPublicEmail = new TableSchema.TableColumn(schema);
				colvarAdministratorPublicEmail.ColumnName = "AdministratorPublicEmail";
				colvarAdministratorPublicEmail.DataType = DbType.String;
				colvarAdministratorPublicEmail.MaxLength = 100;
				colvarAdministratorPublicEmail.AutoIncrement = false;
				colvarAdministratorPublicEmail.IsNullable = true;
				colvarAdministratorPublicEmail.IsPrimaryKey = false;
				colvarAdministratorPublicEmail.IsForeignKey = false;
				colvarAdministratorPublicEmail.IsReadOnly = false;
				colvarAdministratorPublicEmail.DefaultSetting = @"";
				colvarAdministratorPublicEmail.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAdministratorPublicEmail);
				
				TableSchema.TableColumn colvarAdministratorPrivateEmail = new TableSchema.TableColumn(schema);
				colvarAdministratorPrivateEmail.ColumnName = "AdministratorPrivateEmail";
				colvarAdministratorPrivateEmail.DataType = DbType.String;
				colvarAdministratorPrivateEmail.MaxLength = 100;
				colvarAdministratorPrivateEmail.AutoIncrement = false;
				colvarAdministratorPrivateEmail.IsNullable = true;
				colvarAdministratorPrivateEmail.IsPrimaryKey = false;
				colvarAdministratorPrivateEmail.IsForeignKey = false;
				colvarAdministratorPrivateEmail.IsReadOnly = false;
				colvarAdministratorPrivateEmail.DefaultSetting = @"";
				colvarAdministratorPrivateEmail.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAdministratorPrivateEmail);
				
				TableSchema.TableColumn colvarScreenApplicant = new TableSchema.TableColumn(schema);
				colvarScreenApplicant.ColumnName = "ScreenApplicant";
				colvarScreenApplicant.DataType = DbType.Boolean;
				colvarScreenApplicant.MaxLength = 0;
				colvarScreenApplicant.AutoIncrement = false;
				colvarScreenApplicant.IsNullable = false;
				colvarScreenApplicant.IsPrimaryKey = false;
				colvarScreenApplicant.IsForeignKey = false;
				colvarScreenApplicant.IsReadOnly = false;
				
						colvarScreenApplicant.DefaultSetting = @"((0))";
				colvarScreenApplicant.ForeignKeyTableName = "";
				schema.Columns.Add(colvarScreenApplicant);
				
				TableSchema.TableColumn colvarSMTPHost = new TableSchema.TableColumn(schema);
				colvarSMTPHost.ColumnName = "SMTPHost";
				colvarSMTPHost.DataType = DbType.String;
				colvarSMTPHost.MaxLength = 100;
				colvarSMTPHost.AutoIncrement = false;
				colvarSMTPHost.IsNullable = true;
				colvarSMTPHost.IsPrimaryKey = false;
				colvarSMTPHost.IsForeignKey = false;
				colvarSMTPHost.IsReadOnly = false;
				colvarSMTPHost.DefaultSetting = @"";
				colvarSMTPHost.ForeignKeyTableName = "";
				schema.Columns.Add(colvarSMTPHost);
				
				TableSchema.TableColumn colvarSMTPPort = new TableSchema.TableColumn(schema);
				colvarSMTPPort.ColumnName = "SMTPPort";
				colvarSMTPPort.DataType = DbType.Int32;
				colvarSMTPPort.MaxLength = 0;
				colvarSMTPPort.AutoIncrement = false;
				colvarSMTPPort.IsNullable = true;
				colvarSMTPPort.IsPrimaryKey = false;
				colvarSMTPPort.IsForeignKey = false;
				colvarSMTPPort.IsReadOnly = false;
				colvarSMTPPort.DefaultSetting = @"";
				colvarSMTPPort.ForeignKeyTableName = "";
				schema.Columns.Add(colvarSMTPPort);
				
				TableSchema.TableColumn colvarSMTPLoginName = new TableSchema.TableColumn(schema);
				colvarSMTPLoginName.ColumnName = "SMTPLoginName";
				colvarSMTPLoginName.DataType = DbType.String;
				colvarSMTPLoginName.MaxLength = 50;
				colvarSMTPLoginName.AutoIncrement = false;
				colvarSMTPLoginName.IsNullable = true;
				colvarSMTPLoginName.IsPrimaryKey = false;
				colvarSMTPLoginName.IsForeignKey = false;
				colvarSMTPLoginName.IsReadOnly = false;
				colvarSMTPLoginName.DefaultSetting = @"";
				colvarSMTPLoginName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarSMTPLoginName);
				
				TableSchema.TableColumn colvarSMTPLoginPassword = new TableSchema.TableColumn(schema);
				colvarSMTPLoginPassword.ColumnName = "SMTPLoginPassword";
				colvarSMTPLoginPassword.DataType = DbType.String;
				colvarSMTPLoginPassword.MaxLength = 50;
				colvarSMTPLoginPassword.AutoIncrement = false;
				colvarSMTPLoginPassword.IsNullable = true;
				colvarSMTPLoginPassword.IsPrimaryKey = false;
				colvarSMTPLoginPassword.IsForeignKey = false;
				colvarSMTPLoginPassword.IsReadOnly = false;
				colvarSMTPLoginPassword.DefaultSetting = @"";
				colvarSMTPLoginPassword.ForeignKeyTableName = "";
				schema.Columns.Add(colvarSMTPLoginPassword);
				
				TableSchema.TableColumn colvarSMTPUseSSL = new TableSchema.TableColumn(schema);
				colvarSMTPUseSSL.ColumnName = "SMTPUseSSL";
				colvarSMTPUseSSL.DataType = DbType.Boolean;
				colvarSMTPUseSSL.MaxLength = 0;
				colvarSMTPUseSSL.AutoIncrement = false;
				colvarSMTPUseSSL.IsNullable = false;
				colvarSMTPUseSSL.IsPrimaryKey = false;
				colvarSMTPUseSSL.IsForeignKey = false;
				colvarSMTPUseSSL.IsReadOnly = false;
				
						colvarSMTPUseSSL.DefaultSetting = @"((1))";
				colvarSMTPUseSSL.ForeignKeyTableName = "";
				schema.Columns.Add(colvarSMTPUseSSL);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["SurveyHost"].AddSchema("HostConfiguration",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("HostName")]
		public string HostName 
		{
			get { return GetColumnValue<string>("HostName"); }

			set { SetColumnValue("HostName", value); }

		}

		  
		[XmlAttribute("SurveyName")]
		public string SurveyName 
		{
			get { return GetColumnValue<string>("SurveyName"); }

			set { SetColumnValue("SurveyName", value); }

		}

		  
		[XmlAttribute("AdministratorName")]
		public string AdministratorName 
		{
			get { return GetColumnValue<string>("AdministratorName"); }

			set { SetColumnValue("AdministratorName", value); }

		}

		  
		[XmlAttribute("InvitationEmail")]
		public string InvitationEmail 
		{
			get { return GetColumnValue<string>("InvitationEmail"); }

			set { SetColumnValue("InvitationEmail", value); }

		}

		  
		[XmlAttribute("CompletionEmail")]
		public string CompletionEmail 
		{
			get { return GetColumnValue<string>("CompletionEmail"); }

			set { SetColumnValue("CompletionEmail", value); }

		}

		  
		[XmlAttribute("AdministratorPublicEmail")]
		public string AdministratorPublicEmail 
		{
			get { return GetColumnValue<string>("AdministratorPublicEmail"); }

			set { SetColumnValue("AdministratorPublicEmail", value); }

		}

		  
		[XmlAttribute("AdministratorPrivateEmail")]
		public string AdministratorPrivateEmail 
		{
			get { return GetColumnValue<string>("AdministratorPrivateEmail"); }

			set { SetColumnValue("AdministratorPrivateEmail", value); }

		}

		  
		[XmlAttribute("ScreenApplicant")]
		public bool ScreenApplicant 
		{
			get { return GetColumnValue<bool>("ScreenApplicant"); }

			set { SetColumnValue("ScreenApplicant", value); }

		}

		  
		[XmlAttribute("SMTPHost")]
		public string SMTPHost 
		{
			get { return GetColumnValue<string>("SMTPHost"); }

			set { SetColumnValue("SMTPHost", value); }

		}

		  
		[XmlAttribute("SMTPPort")]
		public int? SMTPPort 
		{
			get { return GetColumnValue<int?>("SMTPPort"); }

			set { SetColumnValue("SMTPPort", value); }

		}

		  
		[XmlAttribute("SMTPLoginName")]
		public string SMTPLoginName 
		{
			get { return GetColumnValue<string>("SMTPLoginName"); }

			set { SetColumnValue("SMTPLoginName", value); }

		}

		  
		[XmlAttribute("SMTPLoginPassword")]
		public string SMTPLoginPassword 
		{
			get { return GetColumnValue<string>("SMTPLoginPassword"); }

			set { SetColumnValue("SMTPLoginPassword", value); }

		}

		  
		[XmlAttribute("SMTPUseSSL")]
		public bool SMTPUseSSL 
		{
			get { return GetColumnValue<bool>("SMTPUseSSL"); }

			set { SetColumnValue("SMTPUseSSL", value); }

		}

		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(string varHostName,string varSurveyName,string varAdministratorName,string varInvitationEmail,string varCompletionEmail,string varAdministratorPublicEmail,string varAdministratorPrivateEmail,bool varScreenApplicant,string varSMTPHost,int? varSMTPPort,string varSMTPLoginName,string varSMTPLoginPassword,bool varSMTPUseSSL)
		{
			HostConfiguration item = new HostConfiguration();
			
			item.HostName = varHostName;
			
			item.SurveyName = varSurveyName;
			
			item.AdministratorName = varAdministratorName;
			
			item.InvitationEmail = varInvitationEmail;
			
			item.CompletionEmail = varCompletionEmail;
			
			item.AdministratorPublicEmail = varAdministratorPublicEmail;
			
			item.AdministratorPrivateEmail = varAdministratorPrivateEmail;
			
			item.ScreenApplicant = varScreenApplicant;
			
			item.SMTPHost = varSMTPHost;
			
			item.SMTPPort = varSMTPPort;
			
			item.SMTPLoginName = varSMTPLoginName;
			
			item.SMTPLoginPassword = varSMTPLoginPassword;
			
			item.SMTPUseSSL = varSMTPUseSSL;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(string varHostName,string varSurveyName,string varAdministratorName,string varInvitationEmail,string varCompletionEmail,string varAdministratorPublicEmail,string varAdministratorPrivateEmail,bool varScreenApplicant,string varSMTPHost,int? varSMTPPort,string varSMTPLoginName,string varSMTPLoginPassword,bool varSMTPUseSSL)
		{
			HostConfiguration item = new HostConfiguration();
			
				item.HostName = varHostName;
				
				item.SurveyName = varSurveyName;
				
				item.AdministratorName = varAdministratorName;
				
				item.InvitationEmail = varInvitationEmail;
				
				item.CompletionEmail = varCompletionEmail;
				
				item.AdministratorPublicEmail = varAdministratorPublicEmail;
				
				item.AdministratorPrivateEmail = varAdministratorPrivateEmail;
				
				item.ScreenApplicant = varScreenApplicant;
				
				item.SMTPHost = varSMTPHost;
				
				item.SMTPPort = varSMTPPort;
				
				item.SMTPLoginName = varSMTPLoginName;
				
				item.SMTPLoginPassword = varSMTPLoginPassword;
				
				item.SMTPUseSSL = varSMTPUseSSL;
				
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string HostName = @"HostName";
			 public static string SurveyName = @"SurveyName";
			 public static string AdministratorName = @"AdministratorName";
			 public static string InvitationEmail = @"InvitationEmail";
			 public static string CompletionEmail = @"CompletionEmail";
			 public static string AdministratorPublicEmail = @"AdministratorPublicEmail";
			 public static string AdministratorPrivateEmail = @"AdministratorPrivateEmail";
			 public static string ScreenApplicant = @"ScreenApplicant";
			 public static string SMTPHost = @"SMTPHost";
			 public static string SMTPPort = @"SMTPPort";
			 public static string SMTPLoginName = @"SMTPLoginName";
			 public static string SMTPLoginPassword = @"SMTPLoginPassword";
			 public static string SMTPUseSSL = @"SMTPUseSSL";
						
		}

		#endregion
	}

}

